package com.hu.create;

/**
 * @author 00355760
 * @功能：
 * @版本： V1
 * @版权： 信息技术有限公司（http://www.mychery.com/）
 * @作者： 磐石战队开发组  00355760
 * @日期： 2024/9/19 13:56
 */
public class RunnableTest2 implements Runnable{
    private int tickets = 10;
    @Override
    public synchronized void run() {
        while (true) {
            if (tickets <= 0) {
                break;
            }
            try {
                Thread.sleep(100);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println(Thread.currentThread().getName() + "拿到了第" + tickets-- + "张票");
        }
    }
    public static void main(String[] args) {
        RunnableTest2 runnableTest2 = new RunnableTest2();
        new Thread(runnableTest2, "小红").start();
        new Thread(runnableTest2, "小明").start();
        new Thread(runnableTest2, "小黄牛").start();
    }
}
